package dahuiji.regist.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dahuiji.common.servlet.BaceServlet;
import dahuiji.common.util.Constants;
import dahuiji.common.util.EncodingFormat;
import dahuiji.regist.service.RegistService;

public class CheckName extends BaceServlet {

	/**
	 * Constructor of the object.
	 */
	public CheckName() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * Initialization of the servlet. <br>
	 * 
	 * @throws ServletException
	 *             if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

	@Override
	public String perform(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		request.setCharacterEncoding("UTF-8");
		String name = request.getParameter("name");
		RegistService registService = null;
		boolean result = true;// 返回true说明已经被占用，返回fals说明没有被占用
		if (name != null || !name.equals("")) {
			registService = new RegistService();
			result = registService.checkName(name);
			if (result) {// 被占用
				response.getWriter().print(Constants.NAME_HAVE_UES);
			} else {
				response.getWriter().print(Constants.NAME_NO_UES);
			}
		}
		return null;
	}

}
